const glob = require('glob');
const files = glob.sync('src/**/*.ts');
const path = require('path')
let entries = {};

const isNode = process.env.TARGET == 'node';

files.forEach(file => {
  let nm = file.replace(/src\//, '');
  nm = nm.replace(/\.ts$/, '');
  entries[nm] = path.resolve(__dirname, file);
})

module.exports = {
  entry: entries,
  mode: 'production',
  target: isNode ? 'node' : 'web',
  optimization: {
    minimize: false
  },
  resolve: {
    extensions: ['.js', '.jsx', '.ts', '.tsx']
  },
  output: {
    filename: '[name].js',
    library: 'Thanos',
    libraryTarget: 'umd',
    path: path.resolve(__dirname, 'dist')
  },
  module: {
    //解决Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
    unknownContextCritical: false,
    rules: [
      {
        test: /\.ts[x]?$/,
        use: 'awesome-typescript-loader'
      }
    ]
  }
}